<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>JSfuck Decoder | De-Obfuscator</title>
    <meta name="description" content=
    "JSFuck decoder, de-obfuscator">
    <meta property="og:title" content="JSFuck de-obfuscator">
    <meta property="og:type" content="article">
    <meta property="og:url" content=
    "https://enkhee-osiris.github.io/Decoder-JSFuck/">
    <meta property="og:description" content=
    "JSFuck decoder, de-obfuscator">
    <link rel="icon" href="assets/favicon-16x16.png" sizes="16x16">
    <link rel="icon" href="assets/favicon-32x32.png" sizes="32x32">
    <link rel="shortcut icon" href=
    "assets/android-chrome-192x192.png" sizes="196x196">
    <link rel="shortcut icon" href=
    "assets/android-chrome-512x512.png" sizes="512x512">
    <link rel="apple-touch-icon" href=
    "assets/apple-touch-icon.png">
    <link rel="icon" href="assets/favicon.ico">
    <style type="text/css">
        @import 'https://fonts.googleapis.com/css?family=Open+Sans:300';
        * {
            margin: 0;
            padding: 0;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
        }
        body {
            position: relative;
            height: 100vh;
            padding: 20px;
            text-align: left;
            font-family: Lato;
            color: #fff;
            background: #52B3D9;
            font-family: 'Open Sans', sans-serif;
            text-align: center;
        }
        body div + div {
            margin-top: 1rem;
        }
        h1 {
            font-weight: 300;
            font-size: 40px;
            text-transform: uppercase;
            text-align: center;
            margin: 20px 0;
        }
        textarea {
            display: block;
            clear: both;
            margin-bottom: 10px;
            border-radius: 7px;
            padding: 15px 10px;
            font-size: 14px;
            outline: none;
            border: none;
            background-color: #34495E;
            color: #fff;
            -moz-transition: all 0.2s ease-in;
            -o-transition: all 0.2s ease-in;
            -webkit-transition: all 0.2s ease-in;
            transition: all 0.2s ease-in;
        }
        input[type="submit"] {
            margin: 0 auto;
            position: relative;
            vertical-align: top;
            width: 150px;
            height: 60px;
            padding: 0;
            font-size: 22px;
            font-weight: 300;
            color: white;
            text-align: center;
            text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
            background: #2980b9;
            border: 0;
            border-bottom: 2px solid #2475ab;
            cursor: pointer;
            -webkit-box-shadow: inset 0 -2px #2475ab;
            box-shadow: inset 0 -2px #2475ab;
        }
        input[type="submit"]:active {
            top: 1px;
            outline: none;
            -webkit-box-shadow: none;
            box-shadow: none;
        }
        textarea:-ms-input-placeholder {
            color: #fff;
            font-size: 20px;
            font-weight: 300;
            text-transform: uppercase;
        }
        textarea::-moz-placeholder {
            color: #fff;
            font-size: 20px;
            font-weight: 300;
            text-transform: uppercase;
        }
        textarea::-webkit-input-placeholder {
            color: #fff;
            font-size: 20px;
            font-weight: 300;
            text-transform: uppercase;
            box-shadow: none;
            -webkit-appearance: none;
        }
        textarea:hover {
            background-color: #22313F;
            color: #f2f2f2;
        }
        textarea:focus {
            background-color: #1a252f;
            color: #fff;
        }
        textarea {
            height: 550px;
        }
        footer {
            width: calc(100% - 40px);
            position: absolute;
            bottom: 20px;
        }
        footer > p a {
            color: #2980b9;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div>
        <h1>Wanna decode <span style=
        "color: #F0F060">JSFuck?</span></h1>
    </div>
    <div>
        <label for="versions">Choose a JSFuck version:</label>
        <select name="versions" id="versions">
            <option value="0.5.0">
                v0.5.0
            </option>
            <option value="0.4.0">
                v0.4.0
            </option>
            <option value="0.3.0">
                v0.3.0
            </option>
            <option value="0.2.0">
                v0.2.0
            </option>
            <option value="0.1.2">
                v0.1.2
            </option>
        </select> <label for="withEval">&nbsp;&nbsp;With
        eval:</label> <input type="checkbox" id="withEval" name=
        "withEval" value="withEval" checked>
    </div>
    <div>
        <textarea placeholder="Paste your code here!" id="code"
        style="width:100%;min-height:300px"></textarea>
        <input type="submit" onclick="decode()" value="Decode">
    </div>
    <footer>
        <p style="text-align: center">Crafted with <span style=
        "color: #2980b9">♥</span> by <a href=
        "http://github.com/enkhee-Osiris">Osiris</a>.</p>
    </footer>
    <script src="lib/jsfuck@0.5.0.js"></script>
    <script type="text/javascript">

        (function(){
            var select = document.getElementById('versions');
            function handleChange(event) {
                var script = document.querySelector('script[src]');

                var version = event.target.value;
                var link = 'lib/jsfuck@' + version + '.js';

                var jsFuckScript = document.createElement('script');
                jsFuckScript.src = link;
                script.remove();
                document.body.appendChild(jsFuckScript);
            };

            select.addEventListener('change', handleChange);
        })();

        function patternCreator(prefix, postfix) {
            var replacedPrefix = prefix.replace(/[\[\]\(\)\+\!]/g, '\\$&');
            var replacedPostfix = postfix.replace(/[\[\]\(\)\+\!]/g, '\\$&');

            return replacedPrefix + '(.*)' + replacedPostfix;
        }

        function isMatching(string, pattern) {
            var result = string.match(new RegExp(pattern));
            if (result) return result[1];

            return null;
        }

        function setDecoded(decodedCode) {
            var code = document.getElementById('code');
            code.value = eval(decodedCode);
        }

        function decode() {
            var code = document.getElementById('code');
            var withEval = document.getElementById('withEval');

            if (withEval.checked) {
                var functionNames = ['flat', 'fill', 'filter'];
                var prefix = '';
                var postfix = '';
                var result = null;

                for (let i = 0; i < functionNames.length; i++) {
                    var functionName = functionNames[i];

                    if (functionName !== 'filter') {
                        prefix = '[][' + JSFuck.encode(functionName) + ']' +
                                 '[' + JSFuck.encode('constructor') + ']' +
                                 '(' + JSFuck.encode('return eval') + ')()(';
                        postfix = ')';
                        result = isMatching(code.value, patternCreator(prefix, postfix));

                        if (result) {
                            setDecoded(result);

                            break;
                        }
                    }

                    prefix = '[][' + JSFuck.encode(functionName) + ']' +
                             '[' + JSFuck.encode('constructor') + '](';
                    postfix = ')()';
                    result = isMatching(code.value, patternCreator(prefix, postfix));

                    if (result) {
                        setDecoded(result);

                        break;
                    }
                }
            } else {
                setDecoded(code.value);
            }
        }
    </script>
</body>
</html>
